import Vue from 'vue'
import axios from 'axios'


axios.defaults.baseURL=process.env.VUE_APP_baseURL;
//拦截器
axios.interceptors.request.use(function (config) { 
    const token = localStorage.getItem('token');  
    config.headers.common['Authorization'] = 'Bearer '+token;
    						
    return config;
 }, function (error) {   
    return Promise.reject(error);
 });
//响应拦截
axios.interceptors.response.use(function (response) {
    console.log(response);  
    return response;
 }, function (error) { 
    return Promise.reject(error);
  });
//求情数据封装
const mtAxios = {
    get:(url,params)=>{
        return axios.get(url,{params})
    },
    post:(url,params)=>{
        return axios.post(url,params)
    }
}
//注册全局
Vue.prototype.$http = mtAxios;
//导出
export default mtAxios;